<?php
namespace app\index\controller;

use think\View;

class Friend extends CheckMember
{
    /**
     * 约酒交友
     * @return \think\response\View
     */
    public function index()
    {
        if (request()->isAjax()) {
            $tag = input('param.tag');
            $view = new View();
            $data = ['code' => 200];
            $param = input('param.');
            $param['member_id'] = session('member_id');
            switch ($tag) {
                case 0:
                    $data = local_invoke_api('get_activity_list_bu_where', $param);
                    $view->assign('data', $data['data']);
                    break;
                case 1:
                    break;
                case 2:
                    break;
                case 3:
                    $data = local_invoke_api('get_member_rong_info', $param);
                    $view->assign('data', $data['data']);
                    break;
            }
            $tpl = $view->fetch('index_' . $tag);
            $data['tpl'] = $tpl;
            return json($data);
        } else {
            return view();
        }
    }

    /**
     * 获取附近活动
     * @return \think\response\Json
     */
    public function get_nearby_activity() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = local_invoke_api('get_activity_list_bu_where', $param);
        return json($data);
    }

    /**
     * 申请约酒交友活动
     * @return \think\response\Json
     */
    public function send_activity() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = local_invoke_api('send_activity', $param);
        return json($data);
    }

    /**
     * 设置活动讨论组ID
     * @return \think\response\Json
     */
    public function save_activity_discussion_id() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = local_invoke_api('save_activity_discussion_id', $param);
        return json($data);
    }

    /**
     * 活动提交之后的赞助页面
     * @return \think\response\View
     */
    public function sponsor() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('get_sponsor_list', $param);
        if (!$data['data']) {
            echo '<script>window.location.href="/index/order/pay?model=activity&id=' . $param['id'] . '"</script>';
//            $this->redirect('order/pay?model=activity&id=' . $param['id']);
        } else {
            $this->assign('id', input('param.id'));
            $this->assign('data', $data['data']);
            return view();
        }
    }

    /**
     * 申请赞助
     * @return \think\response\Json
     */
    public function apply_for_sponsor() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = local_invoke_api('apply_for_sponsor', $param);
        return json($data);
    }


}
